package cn.xiaopengstack.domain.activity.service.trialcal;

import cn.xiaopengstack.domain.activity.model.entity.*;
import cn.xiaopengstack.domain.activity.model.valobj.UserGroupBuyOrderVO;
import cn.xiaopengstack.domain.activity.repository.IActivityRepository;
import cn.xiaopengstack.domain.activity.repository.IGroupBuyOrderRepository;
import cn.xiaopengstack.domain.activity.service.trialcal.factory.DefaultActivityStrategyFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jiangyangang
 * 首页商品试算服务
 */
@Service
public class IIndexGroupBuyMarketServiceImpl implements IIndexGroupBuyMarketService {

    @Resource
    private DefaultActivityStrategyFactory factory;

    @Resource
    private IActivityRepository activityRepository;

    @Resource
    private IGroupBuyOrderRepository groupBuyOrderRepository;

    @Override
    public TrialCalculateEntity trialCalculate(MarketProductEntity param) throws Exception {
        return factory.strategyHandler().apply(param, new DefaultActivityStrategyFactory.DynamicContext());
    }

    @Override
    public List<GroupBuyOrderDetailEntity> queryInProgressGroupOrderList(QueryInProgressGroupBuyOrderEntity queryInProgressGroupBuyOrderEntity) {
        return activityRepository.queryInProgressGroupOrderList(queryInProgressGroupBuyOrderEntity);
    }

    @Override
    public List<GroupBuyOrderDetailEntity> queryInProgressGroupOrderListRandom(QueryInProgressGroupBuyOrderEntity queryInProgressGroupBuyOrderEntity) {
        return activityRepository.queryInProgressGroupOrderListRandom(queryInProgressGroupBuyOrderEntity);
    }

    @Override
    public TeamStatisticEntity queryTeamStatistic(Long activityId, String goodsId) {
        return activityRepository.queryTeamStatistic(activityId, goodsId);
    }

    @Override
    public List<UserGroupBuyOrderVO> queryUserGroupBuyList(String userId) {
        return groupBuyOrderRepository.queryUserGroupOrderList(userId);
    }
}
